package com.example.constellation.Activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.constellation.Adapter.fg3listadapter;
import com.example.constellation.R;
import com.example.constellation.bean.YsBean;
import com.example.constellation.bean.YsitemBean;
import com.example.constellation.utils.LoadData;
import com.example.constellation.utils.URLcontent;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;

public class fg3ysActivity extends AppCompatActivity implements LoadData.ongetnetdata {
    private TextView title;
    private ImageView back;
    private ListView fg3list;
    private List<YsitemBean> mdatas;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fg3ys);
        Intent intent = getIntent();
        String name = intent.getStringExtra("name");
        //获取网址
        String ysurl = URLcontent.getysurl(name);
        title=findViewById(R.id.title);
        back=findViewById(R.id.title_back);
        fg3list=findViewById(R.id.fg3list);
        title.setText(name+"今年运势");
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        //获取网络请求
        mdatas=new ArrayList<>();
        LoadData task = new LoadData(this, this, true);
        task.execute(ysurl);

    }
    //网络数据获取成功
    @Override
    public void onsucess(String json) {
        if (!TextUtils.isEmpty(json)) {
            //数据解析
            YsBean ysBean = new Gson().fromJson(json, YsBean.class);
            //显示在listview上进行数据整理 整理成集合
            adddatatolist(ysBean);
            //设置适配器
            fg3listadapter fg3listadapter = new fg3listadapter(this, mdatas);
            fg3list.setAdapter(fg3listadapter);
        }
    }

    //整理数据到集合中
    private void adddatatolist(YsBean ysBean) {
        YsitemBean lib1=new YsitemBean("综合运势",ysBean.getMima().getText().get(0), Color.BLUE);
        YsitemBean lib2=new YsitemBean("爱情运势",ysBean.getLove().get(0),Color.GREEN);
        YsitemBean lib3=new YsitemBean("事业运势",ysBean.getCareer().get(0),Color.GRAY);
        YsitemBean lib4=new YsitemBean("健康运势",ysBean.getHealth().get(0),Color.RED);
        YsitemBean lib5=new YsitemBean("财富运势",ysBean.getFinance().get(0),Color.BLACK);
        mdatas.add(lib1);
        mdatas.add(lib2);
        mdatas.add(lib3);
        mdatas.add(lib4);
        mdatas.add(lib5);
    }
}
